/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.cursojava.server.bd.dvd;

import br.com.cursojava.client.dao.dvd.DvdTGWT;
import br.com.cursojava.client.dao.dvd.GWTServiceDvd;
import br.com.cursojava.server.bd.ConexaoPostgres;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.sql.PreparedStatement;
import java.util.Vector;

/**
 *
 * @author Zacarias
 */
public class GWTServiceDvdImpl extends RemoteServiceServlet implements GWTServiceDvd {

    @Override
    public Boolean inserir(DvdTGWT dvdTGWT) {
        try {
            ConexaoPostgres conexao = new ConexaoPostgres();
           conexao.getConnection();
           PreparedStatement ps = conexao.getConection().prepareStatement
                   ("Insert into \"DVD\" (\"titulo\", \"sinopse\") Values (?,?)");
           ps.setString(1, dvdTGWT.getNome());
           ps.setString(2, dvdTGWT.getSinopse());
           ps.execute();
           //String comando = "Insert into \"Livro\" (\"titulo\", \"autor\") Values"
           //        + "(" + livroTGWT.getNome() + ", "
           //        + livroTGWT.getAutor() + ");";
           
           conexao.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        } 
        return true;
    }

    @Override
    public Vector<DvdTGWT> consultarDvds() {
        Vector<DvdTGWT> retorno = new Vector<DvdTGWT>();
        try {
            ConexaoPostgres conexao = new ConexaoPostgres();
            conexao.getConnection();
            conexao.setResultSet("Select * from \"DVD\"");
            conexao.resultSet.beforeFirst();
            while(conexao.resultSet.next()){
                DvdTGWT dvd = new DvdTGWT();
                dvd.setSinopse(conexao.resultSet.getString("sinopse"));
                dvd.setNome(conexao.resultSet.getString("titulo"));
                retorno.add(dvd); 
            
            }
            conexao.close();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return retorno;
        
    }


    
}
